

setClass("FixCouponBond",
		representation=list(
				
				CouponRate="numeric",
				CouponFrequency="numeric"	
				
		),contains=c("ZeroCouponBond")
)



FixCouponBond <- function(CouponRate,CouponFrequency,Nominal,Currency,Name,SituationDate,MaturityDate,DayCountConvention,Exchange){
	
	EffectiveDate <- SituationDate
	new("FixCouponBond",
			CouponRate=CouponRate,
			CouponFrequency=CouponFrequency,
			Nominal=Nominal,
			Currency=Currency,
			Name=Name,
			SituationDate=SituationDate,
			EffectiveDate=EffectiveDate,
			MaturityDate=MaturityDate,
			DayCountConvention=DayCountConvention,
			Exchange=Exchange)
}

# B1 <- FixCouponBond(3.75,1,500,"CHF","BBB",Sys.Date(),DateYMD(2020,11,30),"30/360","SWISSEXCHANGE")

setMethod("show","FixCouponBond",function(object){
			cat("Fix Coupon Bond\n")
			cat("Name:         ",name(object),"\n",sep="")
			cat("Currency:     ",currency(object),"\n",sep="")
			cat("Coupon:       ",object@CouponRate,"\n",sep="")
			cat("Frequency:    ",object@CouponFrequency,"\n",sep="")
			cat("MaturityDate: ",as.character(object@MaturityDate),"\n",sep="")
			cat("Nominal:      ",cashNumberToText(object@Nominal),"\n",sep="")
		})

setMethod("generateCashFlows","FixCouponBond",function(object){
			EffectiveDate <- object@EffectiveDate
			MaturityDate <- object@MaturityDate
			officialInterestDates <- monthlyDateSequence(EffectiveDate,MaturityDate,object@CouponFrequency,Direction=-1,overlapping=TRUE,keepEndOfMonth=TRUE)
			interestPaymentDates <- getTradingDay(officialInterestDates,Exchange=object@Exchange,Direction=1)
			n <- length(interestPaymentDates)
			CashFlow <- accruedInterest(object@CouponRate,object@DayCountConvention,object@CouponFrequency,interestPaymentDates[1:(n-1)],interestPaymentDates[2:n],interestPaymentDates[2:n])
			CashFlow[n-1] <- CashFlow[n-1] + 100
			CashFlow <- CashFlow/100 * object@Nominal
			CashFlow(object@Currency,object@Name,interestPaymentDates[-1],CashFlow)
		})



